﻿using PersistentObject.Common;
using PersistentObject.Common.Schema;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PersistentObject.Oracle11GR2
{
    public class NamingPatternForOracle : BaseDialectNamingPattern
    {
        public override string GetSaveParameterName(Common.Schema.Column column)
        {
            Table table = column.Table;
            var tableAlias = GetTableAlias(table);
            string pname = string.Format(":{0}__{1}", tableAlias, column.ColumnName);
            return pname;
        }

        public override string GetDeleteParameterName(Common.Schema.Column column)
        {
            string pname = ":" + GetColumnAlias(column);
            return pname;
        }

        public override string GetOperandValueParameterName(Common.Criteria.OperandValue ov)
        {
            string pname = string.Format(":{0}", ov.ParameterName);
            return pname;
        }

        public override string GetColumnNameWithTableNameInQuote(Column column)
        {
            var table = column.Table;
            var clause = string.Format("\"{0}\".\"{1}\"",
                table.TableName,
                column.ColumnName);
            return clause;
        }

        public override string GetColumnNameWithTableAliasInQuote(Column column)
        {
            var table = column.Table;
            var tableAlias = GetTableAlias(table);
            var clause = string.Format("\"{0}\".\"{1}\"",
                tableAlias,
                column.ColumnName
            );
            return clause;
        }

        public override string GetColumnNameInQuote(Column column)
        {
            var clause = string.Format("\"{0}\"", column.ColumnName);
            return clause;
        }

        public override string GetColumnAliasInQuote(Column column)
        {
            var alias = GetColumnAlias(column);
            var clause = string.Format("\"{0}\"", alias);
            return clause;
        }

        public override string GetTableNameInQuote(Table table)
        {
            var clause = string.Format("\"{0}\"", table.TableName);
            return clause;
        }

        public override string GetTableAliasInQuote(Table table)
        {
            var tableAlias = GetTableAlias(table);
            var clause = string.Format("\"{0}\"", tableAlias);
            return clause;
        }
    }
}
